package com.qd.qx.utils;

import android.util.Base64;

import java.io.UnsupportedEncodingException;

/**
 * Code is far away from bug with the animal protecting
 * Author：YS on 2018/10/29
 * Function：default
 */
public class Base64Utils {
    /**
     * 加密
     * oldWord：需要加密的文字/比如密码
     */
    public static String setEncryption(String oldWord) {
        String encodeWord = "";
        try {
            encodeWord = Base64.encodeToString(oldWord.getBytes("utf-8"), Base64.NO_WRAP);

        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return encodeWord;

    }

    /**
     * 解密
     * encodeWord：加密后的文字/比如密码
     */
    public static String setDecrypt(String encodeWord) {
        String decodeWord = "";
        try {
            decodeWord = new String(Base64.decode(encodeWord, Base64.NO_WRAP), "utf-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

        return decodeWord;
    }
}
